<?php
/* -----------------------------------------------------------------
 *                        Aveghe My Blog
 * -----------------------------------------------------------------
 * Aveghe My Blog: made your blog easy!
 * Copyright (C) 2008 Elia Contini
 * 
 * Aveghe My Blog is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * Aveghe My Blog is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 */

class Aveghe_View_Helper_Head
	{
		public function head($element, $area, $data)
			{
				require_once 'Aveghe/Info.php';
				$info = new Aveghe_Info();
				$result = '';
				
				switch($element)
					{
						case 'meta'    :
							{
								$result = "\r\t<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=UTF-8\" />\n";
					
								if(strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false || stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml"))
									header("Content-type: application/xhtml+xml; charset=UTF-8");
								else
									{
										header("Content-type: text/html; charset=UTF-8");
										$result = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n";
									}
								
								$result .= "\t<meta name=\"Author\" content=\"".$data['site_author']."\" />\n";
								$result .= "\t<meta name=\"Description\" content=\"".$data['site_description']."\" />\n";
								$result .= "\t<meta name=\"Keywords\" content=\"".$data['site_keywords']."\" />\n";
								$result .= "\t<meta name=\"Language\" content=\"".$data['site_language']."\" />\n";
								$result .= "\t<meta name=\"Generator\" content=\"".$info->getVersion()."\" />\n";
								
								$result .= "\n\t<title>".stripcslashes($data['site_title'])."</title>\n";
								break;
							}
						case 'style'   :
							{ 
								$cssURL = "aveghe/themes/";
								
								if($area == 'admin')
									$cssURL .= 'admin/'.$data['site_admin_theme'].'/';
								else
									$cssURL .= 'public/'.$data['site_public_theme'].'/';
								
								$cssURL .= 'css/';
									
								$result = "\r\t<style type=\"text/css\" media=\"screen\">@import url(\"".BASE_URL.'/'.$cssURL."screen.css\");</style>\n";
								
								if(file_exists($cssURL.'print.css'))
									$result .= "\t<style type=\"text/css\" media=\"print\">@import url(\"".BASE_URL.'/'.$cssURL."print.css\");</style>\n";
								
								if(file_exists($cssURL.'handheld.css'))
									$result .= "\t<style type=\"text/css\" media=\"handheld\">@import url(\"".BASE_URL.'/'.$cssURL."handheld.css\");</style>\n";
								break;
							}
						case 'favicon' :
							{
								
								$faviconURL = BASE_URL."/aveghe/themes/";
								
								if($area == 'admin')
									$faviconURL .= 'admin/'.$data['site_admin_theme'].'/';
								else
									$faviconURL .= 'public/'.$data['site_public_theme'].'/';
								
								$faviconURL .= 'favicon.ico';
								$result = "\r\t<link rel=\"Shortcut Icon\" type=\"image/x-icon\" href=\"".$faviconURL."\" />\n";
								break;
							}
						case 'rss'     :
							{
								if($data['site_rss_uri'] != '')
									$result = "\r\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"rss\" href=\"".$data['site_rss_uri']."\" />\n";
								else
									$result = "\r\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"rss\" href=\"".$data['site_domain'].BASE_URL."/rss\" />\n";
								break;
							}
						default        :
							{
								$result = 'Some problem occurs';
							}	
					}
				
				return $result;
			}
	}
?>